package com.tianchi.lexiang.util;


import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class DatabaseVersionUtil {
	private static final String TAG = "DatabaseVersionUtil";
	private static final String DB_VERSION_XML = "tianchi_db_version";
	private static final String VERSION = "version";
	private static final int DEFAULT_VERSION = 0;
	
	public static int getDBVersion(Context mContext){
		SharedPreferences prefs = mContext.getSharedPreferences(DB_VERSION_XML, Context.MODE_PRIVATE);
		int version = prefs.getInt(VERSION, DEFAULT_VERSION);
		Log.d(TAG, "[getDBVersion] version=>"+version);
		return version;
	}
	
	public static void persistDBVersion(Context mContext,int version){
		SharedPreferences prefs = mContext.getSharedPreferences(DB_VERSION_XML, Context.MODE_PRIVATE);
		prefs.edit().putInt(VERSION,version).commit();
		Log.d(TAG, "[persistDBVersion] version=>"+version);
	}
	
	public static void updateDBVersion(Context mContext){
		int currentVersion = getDBVersion(mContext) + 1;
		Log.d(TAG, "[updateDBVersion] will update db version to ==>" + currentVersion);
		persistDBVersion(mContext, currentVersion);
	}
	
}
